package app.stock.client;

import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import app.stock.common.Constants;
import app.stock.common.Transaction;

public class TransactionPanelEdit extends TransactionPanel {

    public TransactionPanelEdit(Frame owner, Transaction tx) {
        super(owner);
        this.tx = tx;
        initialize();
    }

    private void initialize() {
        jButtonOK.setText(Constants.label_operationSave);
        jButtonOK.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                jButtonOKMouseClicked(evt);
            }
        });
        this.jTextFieldDate.setValue(tx.date);
        this.jComboBoxType.setSelectedItem(tx.type);
        this.jComboBoxCode.setSelectedItem(tx.code);
        this.jTextFieldName.setText(tx.name);
        this.jTextFieldPrice.setValue(tx.price);
        this.jTextFieldAmount.setValue(tx.amount);
        this.jTextFieldShouxufei.setValue(tx.shouxufei);
        this.jTextFieldYinhuashui.setValue(tx.yinhuashui);
        this.jTextFieldGuohufei.setValue(tx.guohufei);
        this.jTextFieldSum1.setValue(tx.sum1);
        this.jTextFieldSum2.setValue(tx.sum2);
    }

    private void jButtonOKMouseClicked(MouseEvent evt) {
        System.out.println("jButtonOK.mouseClicked, event=" + evt);
        contructTransaction();
        sm.updateTransaction(tx);
        this.setVisible(false);
    }

} // @jve:decl-index=0:visual-constraint="28,-3"
